<?php

namespace App\Admin\Controllers;

use App\Models\VersionModel;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class VersionController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new VersionModel(), function (Grid $grid) {
            $grid->column('id',__('ID'))->sortable();
            $grid->column('type',__("类型"))->using([
                1 => '<span class="label bg-green">安卓</span>',
                2 => '<span class="label bg-yellow">ios</span>'
            ]);
            $grid->column('version',__("版本号"));
            $grid->column('is_apk',__("是否apk地址"))->using([
                0 => '<span class="label bg-green">否</span>',
                1 => '<span class="label bg-yellow">是</span>'
            ]);
            $grid->column('is_force',__("是否强制更新"))->using([
                0 => '<span class="label bg-green">否</span>',
                1 => '<span class="label bg-yellow">是</span>'
            ]);
            $grid->column('status',__("状态"))->using([
                1 => '<span class="label bg-yellow">启用</span>',
                2 => '<span class="label bg-yellow">禁用</span>'
            ]);
            $grid->column('url',__("下载地址"));
            $grid->column('content',__("更新描述"));
            $grid->column('created_at',__("创建时间"));
            $grid->column('updated_at',__("更新时间"))->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id','ID');
                $filter->equal('version','版本号');
                $filter->equal('status','状态');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new VersionModel(), function (Show $show) {
            $show->field('id');
            $show->field('version');
            $show->field('type','类型')->using([
                1 => "安卓",
                2 => "ios"
            ]);
            $show->field('is_force','是否强制更新')->using([
                0 => "否",
                1 => "是"
            ]);
            $show->field('is_apk','是否apk地址')->using([
                0 => "否",
                1 => "是"
            ]);
            $show->field('status','状态')->using([
                1 => "启用",
                2 => "禁用"
            ]);
            $show->field('url','下载地址');
            $show->field('content','更新内容');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new VersionModel(), function (Form $form) {
            $form->display('id')->label("ID");
//            $form->text('app_id')->label("设备ID");
            $form->text('version')->label("版本号");
            $form->select('type')->label("类型")->options([1 => "安卓",2 => "ios"])->default(1);;
            $form->select('is_force')->label("是否强制更新")->options([0 => "否",1 => "是"])->default(0);;
            $form->select('is_apk')->label("是否apk地址")->options([0 => "否",1 => "是"])->default(0);;
            $form->select('status')->label("状态")->options([1 => "启用",2 => "禁用"])->default(1);;
            $form->text('url')->label("下载地址");
            $form->editor('content')->label("更新内容");

            $form->display('created_at')->label("创建时间");
            $form->display('updated_at')->label("更新时间");
        });
    }
}
